package com.only4play.system.infrastructure.converter;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.only4play.system.domain.message.messagerecord.MsgTypeEnum;
import com.only4play.system.domain.message.messagerecord.NoticeType;
import com.only4play.system.domain.message.messagetemplate.TemplateType;
import java.util.Map;

/**
 * 枚举自定义转化 在实体类中的枚举都要进行配置
 */
public class CustomMapper {

  public NoticeType int2NoticeType(Integer code){
    return NoticeType.of(code).orElse(null);
  }

  public Integer noticeType2Int(NoticeType noticeType){
    return noticeType.getCode();
  }

  public MsgTypeEnum int2MsgTypeEnum(Integer code){
    return MsgTypeEnum.of(code).orElse(null);
  }

  public Integer msgTypeEnum2Int(MsgTypeEnum msgTypeEnum){
    return msgTypeEnum.getCode();
  }

  public TemplateType int2TemplateType(Integer code){
    return TemplateType.of(code).orElse(null);
  }

  public Integer templateType2Int(TemplateType templateType){
    return templateType.getCode();
  }

  public Map<String,Object> string2Map(String str){
    JSONObject  jsonObject = JSONObject.parseObject(str);
    return jsonObject;
  }

  public String map2String(Map<String,Object> map){
    return JSON.toJSONString(map);
  }
}
